import { BasicColumn, FormSchema } from "/@/components/Table"
import { render } from "/@/utils/common/renderUtils"
import { DescItem } from "/@/components/Description/index"
import { useI18n } from "/@/hooks/web/useI18n"
import { listDataGroupTree } from "/@/api/infra/dataGroup"
import { DataGroupBizType } from "/@/components/BizDataGroup/index"
const { t } = useI18n("")

export const columns: BasicColumn[] = [
  {
    title: t("名称"),
    dataIndex: "displayName",
    width: 100,
  },
  {
    title: t("表名"),
    dataIndex: "tableName",
    width: 100,
  },
  {
    title: t("表注释"),
    dataIndex: "tableComment",
    width: 100,
  },
  {
    title: t("数据源"),
    dataIndex: "datasourceName",
    width: 100,
  },
  {
    title: t("所属组"),
    dataIndex: "groupName",
    width: 100,
  },

  {
    title: t("创建时间"),
    dataIndex: "updatedAt",
    width: 150,
    align: "center",
  },
]

export const searchFormSchema: FormSchema[] = [
  {
    label: t("表名称"),
    field: "tableName",
    component: "Input",
  },
]

export const inputFormSchemas: FormSchema[] = [
  {
    label: "",
    field: "id",
    component: "Input",
    show: false,
  },
  {
    label: t("显示名称"),
    field: "displayName",
    component: "Input",
    required: true,
    componentProps: {
      maxlength: 300,
    },
  },
  {
    label: t("表名称"),
    field: "tableName",
    component: "Input",
    required: true,
    componentProps: {
      maxlength: 300,
    },
  },
  {
    field: "datasourceId",
    label: "数据源",
    component: "Select",
    required: false,
    componentProps: () => {
      return {
        options: [],
      }
    },
  },
  {
    label: "所属组",
    field: "groupId",
    required: true,
    component: "ApiSelect",
    componentProps: {
      api: listDataGroupTree,
      params: {
        bizType: DataGroupBizType.DATASET,
      },
      optionFilterProp: "label",
      showSearch: true,
      labelField: "name",
      valueField: "id",
      dropdownStyle: { maxHeight: "16vh", overflow: "auto" },
    },
  },
  {
    label: t("表注释"),
    field: "tableComment",
    component: "InputTextArea",
    componentProps: {
      maxlength: 500,
    },
  },
  {
    label: t("备注信息"),
    field: "remark",
    component: "InputTextArea",
    componentProps: {
      maxlength: 500,
    },
    colProps: { lg: 24, md: 24 },
  },
]

export const formDetailSchema: DescItem[] = [
  {
    label: t("名称"),
    field: "displayName",
  },
  {
    label: t("表名"),
    field: "tableName",
  },
  {
    label: t("表注释"),
    field: "tableComment",
  },
  {
    label: t("数据源"),
    field: "datasourceName",
  },
  {
    label: t("所属组"),
    field: "groupName",
  },
  {
    label: t("创建者"),
    field: "createdBy",
  },
  {
    label: t("创建时间"),
    field: "createdAt",
  },
  {
    label: t("更新者"),
    field: "updatedBy",
  },
  {
    label: t("更新时间"),
    field: "updatedAt",
  },
  {
    label: t("备注"),
    labelMinWidth: 40,
    field: "remark",
  },
]
